﻿//===============================================================================
// Copyright © 2011 Allen Lee
// This code released under the terms of the MIT License (http://iridescent.codeplex.com/license)
//===============================================================================
using System;
using System.Collections.Generic;

namespace Iridescent.Utils
{
    public static class Extensions
    {
        public static void ForEach<T>(this IEnumerable<T> collection, Action<T> action)
        {
            foreach (var item in collection)
            {
                action(item);
            }
        }

        public static string GetChineseDayName(this DayOfWeek dayOfWeek)
        {
            switch (dayOfWeek)
            {
                case DayOfWeek.Friday:
                    return "星期五";
                case DayOfWeek.Monday:
                    return "星期一";
                case DayOfWeek.Saturday:
                    return "星期六";
                case DayOfWeek.Sunday:
                    return "星期日";
                case DayOfWeek.Thursday:
                    return "星期四";
                case DayOfWeek.Tuesday:
                    return "星期二";
                case DayOfWeek.Wednesday:
                    return "星期三";
                default:
                    throw new ArgumentException();
            }
        }

        public static DayOfWeek GetDayOfWeekValue(this string chineseDayName)
        {
            switch (chineseDayName)
            {
                case "星期五":
                    return DayOfWeek.Friday;
                case "星期一":
                    return DayOfWeek.Monday;
                case "星期六":
                    return DayOfWeek.Saturday;
                case "星期日":
                    return DayOfWeek.Sunday;
                case "星期四":
                    return DayOfWeek.Thursday;
                case "星期二":
                    return DayOfWeek.Tuesday;
                case "星期三":
                    return DayOfWeek.Wednesday;
                default:
                    throw new ArgumentException();
            }
        }
    }
}
